<template>
	<view>
		<u-cell-group>
			<u-cell size="large" class="cell" title='昵称'>
				<text slot="value">{{mine.name}}</text>
			</u-cell>
			<u-cell size="large" class="cell" title='手机号'>
				<text slot="value">{{mine.phone}}</text>
			</u-cell>
			<u-cell size="large" class="cell" title='微信账号'>
				<text :class="mine.openId?'':'bl'" slot="value" @click="bindwx">{{mine.openId?'已绑定':'未绑定'}}</text>
			</u-cell>
			<!-- 	<u-cell size="large" class="cell" title='支付宝账号'>
				<text slot="value">{{mine.aliPayId?'已绑定':'未绑定'}}</text>
			</u-cell> -->
			<u-cell size="large" class="cell" title='实名状态'>
				<text :class="mine.isAuth==0?'bl':''" @click="goreal" slot="value">{{mine.isAuth | isAuth}}</text>
			</u-cell>
		</u-cell-group>

		<!-- <button type="default" class="setbtn" @click="jumpnew">修改手机号</button> -->
	</view>
</template>

<script>
	import {
		getinfo,
		loginwx
	} from '@/api/mine'
	export default {
		data() {
			return {
				src: "../../static/tabsIcon/add2.png",
				main: [],
				show: false,
				id: "",
				mine: [],
				openId: "",
				accessToken: "",
				code: "",
			}
		},
		filters: {
			isAuth(text) {
				let str
				if (text == 0) {
					str = '去认证'
				} else if (text == 1) {
					str = '认证中'
				} else if (text == 2) {
					str = '已认证'
				} else if (text == 3) {
					str = '认证失败'
				}
				return str
			}
		},
		onShow() {
			this.getinfo();
		},
		methods: {
			bindwx() {
				if (this.mine.openId) {
					return
				}
				let _that = this
				uni.login({
					provider: 'weixin',
					// onlyAuthorize: true,
					success: function(loginRes) {
						// _that.code = loginRes.code
						_that.loginwx(loginRes.authResult.openid, loginRes.authResult.access_token);
						console.log(loginRes);
					}
				})
			},
			loginwx(openid, accessToken) {
				let data = {
					openId: openid,
					accessToken: accessToken
				}
				loginwx(data).then(res => {
					if (res.success == 1) {
						// if (res.data.token) {
						// 	uni.showToast({
						// 		icon: 'none',
						// 		title: '该微信已绑定过账号！'
						// 	})
						// 	return
						// }
						this.openId = res.data.openId;
						uni.navigateTo({
							url: './bindwx?openId=' + this.openId
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			goreal() {
				if (this.mine.isAuth == 0) {
					uni.navigateTo({
						url: './realname'
					})
				}
			},
			getinfo() {
				getinfo().then(res => {
						if (res.success == 1) {
							this.mine = res.data;
						} else {
							uni.showToast({
								icon: 'none',
								title: res.message
							})
						}
					})
					.catch(err => {

					});
			},
			goadd() {
				uni.navigateTo({
					url: "./addcard"
				})
			},
			jumpnew(){
				uni.navigateTo({
					url:"./setphone"
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: rgb(229, 231, 233);
	}

	.cell {
		background-color: rgb(255, 255, 255);
	}

	.titleyin {
		position: relative;
		padding-top: 100rpx;
		width: 93%;
		height: 80rpx;
		margin: 0 auto;
		left: 0;
		right: 0;
		line-height: 80rpx;
		font-weight: 600;
		// background-color: #1467FF;
	}


	.unbind {
		color: rgba(0, 0, 0, 0.5);
		font-size: 26rpx;
		border-radius: 20rpx;
		border: 2rpx solid rgba(0, 0, 0, 0.5);
		padding: 4rpx 15rpx;
	}

	.bl {
		color: blue;
	}
	.setbtn{
		margin-top: 60upx;
		width: 80%;
		color: #FFFFFF;
		background-color: rgb(252, 103, 88);
		border-radius: 20upx;
	}
</style>
